unit SYS_WF_CURRENT_ITEM;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TSYSWFCURRENTITEM=class(TUniEngine)
  private
    FENTITYID : string;
    FBILLID   : string;      
    FNODEID   : Extended;
    FSTATUSCODE: string;
    FRCID     : Extended;
    FCCID     : Extended;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property ENTITYID : string read FENTITYID  write FENTITYID;
    property BILLID   : string read FBILLID    write FBILLID;
    property NODEID   : Extended read FNODEID    write FNODEID;
    property STATUSCODE: string read FSTATUSCODE write FSTATUSCODE;
    property RCID     : Extended read FRCID      write FRCID;
    property CCID     : Extended read FCCID      write FCCID;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(ASYSWFCURRENTITEM:TSYSWFCURRENTITEM):TSYSWFCURRENTITEM;overload;        
    class procedure CopyIt(ASYSWFCURRENTITEM:TSYSWFCURRENTITEM;var Result:TSYSWFCURRENTITEM);overload;       
  end;

implementation

{ TSYSWFCURRENTITEM }
procedure TSYSWFCURRENTITEM.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('ENTITY_ID').Value := ENTITYID;
        ParamByName('BILL_ID').Value := BILLID;
        ParamByName('NODE_ID').Value := NODEID;
        ParamByName('STATUS_CODE').Value := STATUSCODE;
        ParamByName('RCID').Value := RCID;
        ParamByName('CCID').Value := CCID; 
      end;
      otEdit:
      begin
        ParamByName('ENTITY_ID').Value := ENTITYID;
        ParamByName('BILL_ID').Value := BILLID;
        ParamByName('NODE_ID').Value := NODEID;
        ParamByName('STATUS_CODE').Value := STATUSCODE;
        ParamByName('RCID').Value := RCID;
        ParamByName('CCID').Value := CCID; 
      end;  
      otDelt:
      begin
        ParamByName('ENTITY_ID').Value := ENTITYID;
        ParamByName('BILL_ID').Value := BILLID;
 
      end;  
    end;
  end;
end;

function TSYSWFCURRENTITEM.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('SYS_WF_CURRENT_ITEM',['ENTITY_ID',ENTITYID,'BILL_ID',BILLID],AUniConnection);
end;

function TSYSWFCURRENTITEM.GetNextIdex: Integer;
begin

end;

function TSYSWFCURRENTITEM.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TSYSWFCURRENTITEM.GetStrDelete: string;
begin
  Result:='DELETE FROM SYS_WF_CURRENT_ITEM WHERE   ENTITY_ID=:ENTITY_ID AND BILL_ID=:BILL_ID';
end;

function TSYSWFCURRENTITEM.GetStrInsert: string;
begin
  Result:='INSERT INTO SYS_WF_CURRENT_ITEM'
         +'    ( ENTITY_ID, BILL_ID, NODE_ID, STATUS_CODE, RCID, CCID)'
         +'    VALUES'
         +'    (:ENTITY_ID,:BILL_ID,:NODE_ID,:STATUS_CODE,:RCID,:CCID)';
end;

function TSYSWFCURRENTITEM.GetStrsIndex: string;
begin
  Result:=Format('%S-%S',[ENTITYID,BILLID]);
end;

function TSYSWFCURRENTITEM.GetStrUpdate: string;
begin
  Result:='UPDATE  SYS_WF_CURRENT_ITEM SET'
         +'    NODE_ID=:NODE_ID,'
         +'    STATUS_CODE=:STATUS_CODE,'
         +'    RCID=:RCID,'
         +'    CCID=:CCID'
         +'    WHERE ENTITY_ID=:ENTITY_ID'
         +'    AND   BILL_ID=:BILL_ID';
end;

constructor TSYSWFCURRENTITEM.Create;
begin

end;

destructor TSYSWFCURRENTITEM.Destroy;
begin

  inherited;
end;

class function TSYSWFCURRENTITEM.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  Result:=TSYSWFCURRENTITEM.Create;

  with TSYSWFCURRENTITEM(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='ENTITY_ID' then
      begin
        ENTITYID :=Field.AsString;
      end else
      if FieldName='BILL_ID' then
      begin
        BILLID   :=Field.AsString;
      end else
      if FieldName='NODE_ID' then
      begin
        NODEID   :=Field.AsFloat;
      end else
      if FieldName='STATUS_CODE' then
      begin
        STATUSCODE:=Field.AsString;
      end else
      if FieldName='RCID' then
      begin
        RCID     :=Field.AsFloat;
      end else
      if FieldName='CCID' then
      begin
        CCID     :=Field.AsFloat;
      end;
    end
  end;  
end;

class procedure TSYSWFCURRENTITEM.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TSYSWFCURRENTITEM(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='ENTITY_ID' then
      begin
        ENTITYID :=Field.AsString;
      end else
      if FieldName='BILL_ID' then
      begin
        BILLID   :=Field.AsString;
      end else
      if FieldName='NODE_ID' then
      begin
        NODEID   :=Field.AsFloat;
      end else
      if FieldName='STATUS_CODE' then
      begin
        STATUSCODE:=Field.AsString;
      end else
      if FieldName='RCID' then
      begin
        RCID     :=Field.AsFloat;
      end else
      if FieldName='CCID' then
      begin
        CCID     :=Field.AsFloat;
      end;
    end
  end;  
end;

class function  TSYSWFCURRENTITEM.CopyIt(ASYSWFCURRENTITEM: TSYSWFCURRENTITEM): TSYSWFCURRENTITEM;
begin
  Result:=TSYSWFCURRENTITEM.Create;
  TSYSWFCURRENTITEM.CopyIt(ASYSWFCURRENTITEM,Result)
end;

class procedure TSYSWFCURRENTITEM.CopyIt(ASYSWFCURRENTITEM:TSYSWFCURRENTITEM;var Result:TSYSWFCURRENTITEM);
begin
  if Result=nil then Exit;
  Result.ENTITYID :=ASYSWFCURRENTITEM.ENTITYID;
  Result.BILLID   :=ASYSWFCURRENTITEM.BILLID;
  Result.NODEID   :=ASYSWFCURRENTITEM.NODEID;
  Result.STATUSCODE:=ASYSWFCURRENTITEM.STATUSCODE;
  Result.RCID     :=ASYSWFCURRENTITEM.RCID;
  Result.CCID     :=ASYSWFCURRENTITEM.CCID;
end;

end.

